/******************************************************************************
 
 @File         block.cpp
 
 @Title        
 
 @Version      
 
 @Copyright    Copyright (c) Innorient Limited.
 
 @Platform     Independent
 
 @Description  
 text
 
 ******************************************************************************/

class Blocks 
{
protected:
	int i,j;

public: 	
	int trangthai;
	int current[4][4];
	int block1[4][16];
	int block2[4][16];
    
public:
    Blocks();
    Blocks(int* block_in, int tt);
    int color_getout();
    void get_in(int* block_in, int tt);
    void onup(int block);
};
	
	
Blocks::Blocks(int* block_in,int tt)
{
    for (i=0;i<4;i++)
    for (j=0;j<16;j++)
        block1[i][j] = block_in[4*i+j];
    trangthai=tt;
}

Blocks::Blocks()
{
}

int Blocks::color_getout()
{
    for (i=0;i<4;i++)
    for (j=0;j<16;j++)						
        if(block1[i][j] != 0)
            return block1[i][j];
    
    return 0;
}

void Blocks::get_in(int *block_in,int tt)
{		
    for (i=0;i<4;i++)
    for (j=0;j<16;j++)
        block1[i][j]=block_in[4*i+j];	
    trangthai=tt;
}

void Blocks::onup(int block)
{
    int block1[4][16]=	{ 
                            1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,
                            1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                        };
    int block2[4][16]=  {
                            2,0,0,0,2,2,2,2,2,0,0,0,2,2,2,2,
                            2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,
                            2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,
                            2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0
                        };
    int block3[4][16]=	{
                            3,3,3,0,3,0,0,0,0,3,0,0,0,3,0,0,
                            0,3,0,0,3,3,0,0,3,3,3,0,3,3,0,0,
                            0,0,0,0,3,0,0,0,0,0,0,0,0,3,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                        };
    int	block4[4][16]=	{
                            4,0,0,0,0,0,4,0,4,4,0,0,4,4,4,0,
                            4,0,0,0,4,4,4,0,0,4,0,0,4,0,0,0,
                            4,4,0,0,0,0,0,0,0,4,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                        };
    int	block5[4][16]=	{
                            0,5,0,0,5,5,5,0,5,5,0,0,5,0,0,0,
                            0,5,0,0,0,0,5,0,5,0,0,0,5,5,5,0,
                            5,5,0,0,0,0,0,0,5,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                        };
    int	block6[4][16]=	{
                            0,6,6,0,6,0,0,0,0,6,6,0,6,0,0,0,
                            6,6,0,0,6,6,0,0,6,6,0,0,6,6,0,0,
                            0,0,0,0,0,6,0,0,0,0,0,0,0,6,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                        };
    int	block7[4][16]=  {
                            7,7,0,0,0,7,0,0,7,7,0,0,0,7,0,0,
                            0,7,7,0,7,7,0,0,0,7,7,0,7,7,0,0,
                            0,0,0,0,7,0,0,0,0,0,0,0,7,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                        };

    if (trangthai == 3)
        trangthai = 0; 
    else
        trangthai = trangthai + 1;

    for (int i=0;i<=3;i++)
        for (int j=0;j<=3;j++)
        {
            if (block==1)
                current[i][j]=block1[i][j+trangthai*4];
            if (block==2)
                current[i][j]=block2[i][j+trangthai*4];
            if (block==3)
                current[i][j]=block3[i][j+trangthai*4];
            if (block==4)
                current[i][j]=block4[i][j+trangthai*4];
            if (block==5)
                current[i][j]=block5[i][j+trangthai*4];
            if (block==6)
                current[i][j]=block6[i][j+trangthai*4];
            if (block==7)
                current[i][j]=block7[i][j+trangthai*4];
        }
}